package com.coolw.design.pattern.behavior.liabilitychain.config;

import com.coolw.design.pattern.behavior.liabilitychain.handler.OrderCheckHandler;
import com.coolw.design.pattern.behavior.liabilitychain.handler.impl.AddressCheckHandler;
import com.coolw.design.pattern.behavior.liabilitychain.handler.impl.OrderIdCheckHandler;
import com.coolw.design.pattern.behavior.liabilitychain.handler.impl.UserCheckHandler;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 订单检查配置
 *
 * @author coolw
 * @date 2024/10/22 19:44
 */
@Configuration
public class OrderCheckConfig {

    @Bean
    public UserCheckHandler userCheckHandler() {
        return new UserCheckHandler();
    }

    @Bean
    public OrderIdCheckHandler orderIdCheckHandler() {
        return new OrderIdCheckHandler();
    }

    @Bean
    public AddressCheckHandler addressCheckHandler() {
        return new AddressCheckHandler();
    }

    /**
     * 设置处理链
     */
    @Bean
    public OrderCheckHandler orderCheckHandler() {
        // 设置第一个处理类
        OrderIdCheckHandler orderIdCheckHandler = this.orderIdCheckHandler();
        // 依次设置下一个处理类
        orderIdCheckHandler.nextHandler(userCheckHandler())
                .nextHandler(addressCheckHandler());
        return orderIdCheckHandler;
    }
}
